#ifndef __Sizeable_h
#define __Sizeable_h

#include <QObject>
#include <QWidget>
#include <QEvent>
#include <QRect>
#include <QPoint>

#include <QDebug>
#include <QApplication>
#include <QWidget>

class Sizeable : public QObject
{
    Q_OBJECT

public:
    Sizeable(QWidget *parent);
    ~Sizeable();

protected:
    enum WidgetRegion
    {
        LEFT_TOP = 0,
        TOP,
        RIGHT_TOP,
        RIGHT,
        RIGHT_BOTTOM,
        BOTTOM,
        LEFT_BOTTOM,
        LEFT,
        INNER,
        UNKNOWN = -1,
    };

public:
    void setBorderWidth(uint width);
    void setEnabled(bool kEnabled);

protected:
    virtual bool eventFilter(QObject *obj, QEvent *event);

private:
    void makeRegions();
    WidgetRegion findRegion(const QPoint &pos);
    void updateGeometry(int x, int y, int w, int h);

    void startCursorTimer();
    void stopCursorTimer();

    QObjectList childrenWidgets(QWidget *pWidget);

private:
    bool _isEnabled;
    QWidget* _sizeableWidget;
    uint _borderWidth;
    QRect _regions[9];

    // pos before drag
    QPoint _originPosGlobal;
    // geo before drag
    QRect _originGeometry;

    // the flag for mouse is pressed
    bool _isPressed;
    // the region of mouse pressed
    WidgetRegion _regionPressed;
    // the timer handler to check cursor
    int _cursorTimerHandler;
};

#endif //__Sizeable_h
